package com.cfgj.service.impl;

import com.cfgj.entity.CrowdFunding;
import com.cfgj.mapper.CrowdFundingMapper;
import com.cfgj.service.CrowdFundingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CrowdFundingServiceImpl implements CrowdFundingService {
    private static Integer CURRENT_PAGE=1;
    private static Integer PAGE_SIZE=5;
    @Autowired
    private CrowdFundingMapper crowdFundingMapper;

    @Override
    public List<CrowdFunding> findCrowfundingbyStatus(String status, Integer page, Integer size) {
        if (page != null){
            CURRENT_PAGE=page;
        }
        if (size!=null){
            PAGE_SIZE=size;
        }
        return crowdFundingMapper.findCrowfundingbyStatus(status,(CURRENT_PAGE-1)*PAGE_SIZE,PAGE_SIZE);
    }


    @Override
    public List<CrowdFunding> findCrowfundingbyname(String keyword, Integer page, Integer size) {
        if (page != null){
            CURRENT_PAGE=page;
        }
        if (size!=null){
            PAGE_SIZE=size;
        }
        return crowdFundingMapper.findCrowfundingbyname(keyword ,(CURRENT_PAGE-1)*PAGE_SIZE,PAGE_SIZE);

    }

    @Override
    public Integer findcount( String status) {
        return crowdFundingMapper.findcount(status);
    }

    @Override
    public void passCrowdFund(Integer crowdId) {
        crowdFundingMapper.passCrowdFund(crowdId);
    }
}
